#ifndef USERDAO_H
#define USERDAO_H

#include "Permission.h"
#include "muduo/base/Mutex.h"

#include <string>
#include <memory>
#include <map>
#include <atomic>

namespace ftp
{

enum class Permission;
struct UserInfo;

class UserDao
{
public:
	UserDao();
	~UserDao();

	bool addUser(const std::string& username, const std::string& password, const std::string& localRootPath, Permission permission);

	std::shared_ptr<UserInfo> getUserInfo(const std::string& username, const std::string& password) const;

	void enableAnonymousUser();

	void disableAnonymousUser();

private:
	void setSupportAnonymousUser(bool val);

	bool isAnonymousUser(const std::string& username) const;

	mutable muduo::MutexLock mutex_;
	std::map<std::string, std::shared_ptr<UserInfo>> database_ GUARDED_BY(mutex_);
	std::shared_ptr<UserInfo> anonymousUserInfo_ GUARDED_BY(mutex_);
	std::atomic<bool> supportAnonymousUser_;
};

} // namespace ftp

#endif // !USERDAO_H
